package com.ysh.dbpool.common;

/**
 * A response info
 * @author yangshuo
 */
public class ResponseInfo {
	/**
	 * Return state
	 * 
	 * @uml.property name="code"
	 */
	private int code;

	/**
	 * Additional info
	 * 
	 * @uml.property name="info"
	 */
	private StringBuffer info;

	/**
	 * Success Info
	 */
	public static final ResponseInfo SUCCESS = new ResponseInfo(0);

	/**
	 * Fail Info
	 */
	public static final ResponseInfo FAIL = new ResponseInfo(1);

	/**
	 * Create A Response Info
	 * 
	 * @param code:State of response info
	 */
	private ResponseInfo(int code) {
		this.code = code;
		this.info = new StringBuffer();
	}

	/**
	 * get additional info
	 * 
	 * @return String
	 * @uml.property name="info"
	 */
	public String getInfo() {
		return this.info.toString();
	}

	/**
	 * append info
	 * 
	 * @param info:info to append
	 */
	public void appendInfo(String info) {
		this.info.append(info + "\n");
	}

	/**
	 * set info
	 * 
	 * @param info:info to set
	 */
	public void setInfo(String info) {
		this.info = this.info.replace(0, this.info.length(), info);
	}

	/**
	 * return the info
	 * 
	 * @return int
	 * @uml.property name="code"
	 */
	protected int getCode() {
		return this.code;
	}

	/**
	 *Check if the param is equal to current object<br>
	 *true if equals,else false
	 * 
	 * @param responseInfo:response info to compare
	 * @return boolean
	 */
	public boolean equals(ResponseInfo responseInfo) {
		return this.code == responseInfo.getCode();
	}
}
